package otcv.hr.util;

/**
 * @author : H-Thien
 * @comment : paging navigator
 */
public class PagingUtil {

	/**
	 * @comment :
	 */
	public static String getPaging(String currentPage, int totalRowCount, String rowPerPage) {
		String navigatorString = getPaging(currentPage, totalRowCount, rowPerPage, 10);

		return navigatorString;
	}

	/**
	 * @comment :
	 */
	public static String getPaging(String currnetPage, int totalRowCount, String rowPerPage, int nPage) {

		String navigatorString = "";

		int cPage = Integer.parseInt(currnetPage);
		int rPage = Integer.parseInt(rowPerPage);

		int totalPage = ((totalRowCount - 1) / rPage) + 1; // totalPage 계산
		int startPage = ((cPage - 1) / nPage) * nPage + 1; // startPage 계산

		// Previous Page
		if (startPage > 1) {
			int movePage = startPage - 1;
			navigatorString += "<a href='#' OnClick=\"javascript:pageMove('1');\"><<</a>&nbsp;<a href='#' OnClick=\"javascript:pageMove('" + movePage + "');\"><</a>";
		}

		// Navigation Page
		for (int i = startPage; i < (startPage + nPage) && i <= totalPage; i++) {
			if (i == cPage) {
				navigatorString += "&nbsp;&nbsp;<font color='red'><strong>" + i + "</strong></font>";
			} else {
				navigatorString += "&nbsp;&nbsp;<a href='#' OnClick=\"javascript:pageMove('" + i + "');\">" + i + "</a>";
			}
		}

		// Next Page
		if (startPage + nPage - 1 < totalPage) {
			int movePage = startPage + nPage;
			navigatorString += "&nbsp;&nbsp;<a href='#' OnClick=\"javascript:pageMove('" + movePage + "');\">></A>&nbsp;<a href='#' OnClick=\"javascript:pageMove('" + totalPage + "');\">>></a>";
		}

		return navigatorString;
	}
}